package io2;

import javax.sound.midi.Soundbank;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * 字符串读取 InputStreamReader
 */
public class ISRDemo {
    public static void main(String[] args) throws IOException {

        File file=new File("osw.txt");
        FileInputStream fis1=new FileInputStream(file);
        FileInputStream fis2=new FileInputStream(file);
        InputStreamReader isr1=new InputStreamReader(fis1, StandardCharsets.UTF_8);
        InputStreamReader isr=new InputStreamReader(fis2, StandardCharsets.UTF_8);
        int d;
        while ((d=isr1.read())!=-1)
        { System.out.println((char)d);}
//文件字节长度33+4+3
        System.out.println();
        System.out.println("长度:"+file.length());
        char[] data=new char[(int)file.length()];
        String s="";
       isr.read(data);
        for (int i = 0; i < data.length; i++) {
            if(((int)data[i])==0)
                return;
            System.out.println(data[i]);
            System.out.println((int)data[i]);
        }
//            s = new String(data);
//       // byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
//
//        System.out.println(s);
    }

}
